<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;

class PtGoodsSpec extends Model
{
    protected $table = 'pt_goods_spec';		//related table name
    protected $guarded = [];

    //访问器：
    public function getPriceAttribute($value)
    {
        try {
            return $value/100;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：
    public function setPriceAttribute($value)
    {
        $this->attributes['price']=$value*100;
    }


    //访问器：
    public function getCostPriceAttribute($value)
    {
        try {
            return $value/100;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：
    public function setCostPriceAttribute($value)
    {
        $this->attributes['cost_price']=$value*100;
    }


    //访问器：
    public function getPostPriceAttribute($value)
    {
        try {
            return $value/100;
        } catch (DecryptException $e) {
            throw $e;
        }
    }


    //修改器：
    public function setPostPriceAttribute($value)
    {
        $this->attributes['post_price']=$value*100;
    }

    //关联到素材表
    public function PtMaterial()
    {
        return $this->hasMany('App\Http\Model\PtMaterial','spec_id');
    }


    //关联到商品表
    public function PtGoods()
    {
        return $this->hasOne('App\Http\Model\PtGoods','id');
    }
}
